//
//  WBMainViewController.swift
//  Swift_WeiBo
//
//  Created by peikua on 17/3/7.
//  Copyright © 2017年 peikua. All rights reserved.
//

import UIKit

class WBMainViewController: UITabBarController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        setupChildControllers()
    }
}

extension WBMainViewController{
    
     func setupChildControllers(){
        let array = [
            ["clsName":"WBHomeViewController","title":"首页"]
        ]
        var my_viewControllers = [UIViewController]()
        
        for dict in array{
           my_viewControllers.append(createViewController(dict: dict))
        }
        viewControllers = my_viewControllers
    }
    
     func createViewController(dict:[String:String]) -> UIViewController{
        
        
        guard let title = dict["title"],
            let clsName = dict["clsName"],
            let cls = (NSClassFromString(Bundle.main.namespace + "." + clsName) as? UIViewController.Type)
        
        else {
            return UIViewController()
        }
        let vc = cls.init()
        vc.title = title
        
        let nav = WBNavigationController(rootViewController: vc)
        return nav
    }
}
